from flask import session

from moldels import db
from moldels.index import Com_car


# 返回总钱数
def total_price(obj, fre):
    user_id = session.get("user_id")
    sum = 0
    for i in obj:
        com_car = db.session.query(Com_car).filter(Com_car.user_id == user_id, Com_car.comd_id == i.id).first()

        sum += int(i.com_price) * int(com_car.comd_count)

    if fre:

        return sum + int(fre)

    else:
        return sum


# 返回商品总件数
def get_count_and_prices(com_id):
    user_id = session.get('user_id')

    com_car = db.session.query(Com_car).filter(Com_car.user_id == user_id, Com_car.comd_id == com_id).first()

    if com_car:
        return com_car.comd_count


def get_order_status(status_id):
    if status_id == "1":
        return "未支付"
    elif status_id == "2":
        return "待发货"
    elif status_id == "3":
        return "运输中"
    elif status_id == "4":
        return "派送中"
    elif status_id == "5":
        return "已送达"
    elif status_id == "6":
        return "订单生成中"
    else:
        return "xxx"


